<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>5.ajax_deal_json</title>
  <style>
    #content{
      width: 300px;
      height: 200px;
      background: aquamarine;
    }
  </style>
</head>
<body>

<div id="content">

</div>
<button id="btn">发送</button>

<script>
    let content =document.getElementById("content");
    let btn =document.getElementById("btn");
    btn.onclick =()=>{
      const xmlHttpRequest = new XMLHttpRequest();
      xmlHttpRequest.onreadystatechange=()=>{
          if (xmlHttpRequest.readyState === 4){
              if(xmlHttpRequest.status >=200 && xmlHttpRequest.status<300){
                  console.log(xmlHttpRequest.response);
              }
          }
      }

      xmlHttpRequest.open("get","./get_json");
      //AJAX默认返回的数据默认是字符串 这里将它转化为对象
      xmlHttpRequest.responseType ="json";
      xmlHttpRequest.send();
    }
</script>
</body>
</html>